﻿using Artech.Common.Properties;
using EnvDTE;
using Microsoft.Practices.Unity.Utility;
using Microsoft.VisualStudio.TextTemplating;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Artech.CodeGeneration
{
    public class TransformContext
    {
        public static TransformContext Current { get; internal set; }
        public TextTransformation Transformation{get; private set;}
        public ITextTemplatingEngineHost Host {get; private set;}
        public DTE Dte { get; private set; }
        public ProjectItem TemplateProjectItem { get; private set; }

        internal TransformContext(TextTransformation transformation, ITextTemplatingEngineHost host)
        {           
            this.Transformation = transformation;
            this.Host = host;
            this.Dte = (DTE)((IServiceProvider)host).GetService(typeof(DTE));
            this.TemplateProjectItem = this.Dte.Solution.FindProjectItem(host.TemplateFile);
        }

        public static void EnsureContextInitialized()
        {
            if (null == Current)
            {
                throw new TransformationException(CoreResources.ExceptionTransformContextNotInitialized);
            }
        }
    }
}
